package com.tjsinfo.tjsoa.chuanyue.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONArray;
import org.json.JSONObject;

import com.tjsinfo.tjsoa.chuanyue.bo.ITChuanyueNeirongBO;
import com.tjsinfo.tjsoa.chuanyue.vo.TChuanyueNeirong;
import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.workflow.WorkFlowTemplate;




/**
 * 组织部发文管理查询发文
 * @author Administrator
 *
 */
public class AdminselectAction extends Action{
	private ITChuanyueNeirongBO neirongBO;
		
	

	public ITChuanyueNeirongBO getNeirongBO() {
		return neirongBO;
	}



	public void setNeirongBO(ITChuanyueNeirongBO neirongBO) {
		this.neirongBO = neirongBO;
	}



	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		String path = request.getContextPath();
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
		List<TChuanyueNeirong> list;
		JSONArray array = new JSONArray();
		JSONObject object = new JSONObject();
		if (request.getParameter("start") == null) {
			
			list = neirongBO.selectPage(0, 23);
		} else {
			Integer first = Integer.parseInt(request.getParameter("start"));
			list = neirongBO.selectPage(first, 23);
		}
		Integer totalProperty = neirongBO.seletPageTotalLine();
		object.put("totalProperty", totalProperty);
		
		for (TChuanyueNeirong neirong : list) {
			JSONObject neirongJSON = new JSONObject();
			neirongJSON.put("biaoti", neirong.getBiaoti());
			neirongJSON.put("neirong", neirong.getNeirong());
			neirongJSON.put("creatdatetime", ToolKit.FormatDate(neirong.getCreatdatetime()) );
			if (workFlowTemplate.isEnd(Long.parseLong(neirong.getFlowid().toString()) )){
				neirongJSON.put("state", "是");
				neirongJSON.put("operate", "<a href='"+basePath+"chuanyue/genzong.jsp?flowid="+neirong.getFlowid()+
						"'>跟踪</a>&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/chuanyue/shenpi.do?method=selectonedoc&id="+neirong.getId()+"'>查看</a>");
						array.put(neirongJSON);
			}
			else if (workFlowTemplate.isSuspend(Long.parseLong(neirong.getFlowid().toString()) )){
				neirongJSON.put("state", "中止");
				neirongJSON.put("operate", "<a href='"+basePath+"chuanyue/genzong.jsp?flowid="+neirong.getFlowid()+
						"'>跟踪</a>&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/chuanyue/shenpi.do?method=selectonedoc&id="+neirong.getId()+"'>查看</a>&nbsp;&nbsp;"+"<a href='javascript:resume("+neirong.getFlowid()+")'>重启</a>");
						array.put(neirongJSON);
			}
			else{
				neirongJSON.put("state", "否");
				neirongJSON.put("operate", "<a href='"+basePath+"chuanyue/genzong.jsp?flowid="+neirong.getFlowid()+
						"'>跟踪</a>&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/chuanyue/shenpi.do?method=selectonedoc&id="+neirong.getId()+"'>查看</a>&nbsp;&nbsp;"+"<a href='javascript:suspend("+neirong.getFlowid()+")'>中止</a>");
						array.put(neirongJSON);
			}
				
			
		}
		request.getSession().setAttribute("chuanyueadminliststart", Integer.parseInt(request.getParameter("start")));
		object.put("root", array);
		response.getWriter().print(object);
		return null;
	}
	
}
